package cs241.lab.BLL;

import java.util.Scanner;
import cs241.lab.Bike.*;
import cs241.lab.BikeList.*;
import cs241.lab.constants.*;

public class BikeStoreBusinessLogic {
	
	private Scanner scan;
	private BikeList bikeList;
	

	public BikeStoreBusinessLogic(){
		scan = new Scanner(System.in);
		bikeList = new BikeList();
		
		this.showBikeMenu();
	}
	
	private void showBikeMenu(){
		System.out.println("Select an Option by choosing the corresponding number:\n");
		
		for(int i = 0; i < Constants.OPTIONS.length; i++){
			System.out.println((i + 1) +". " + Constants.OPTIONS[i]);
		}
		
		this.getUserOptionDecision();
		
	}
	
	private void getUserOptionDecision(){
		int decision = 0;
		
		String selection = scan.nextLine();
		
		try{
			decision = Integer.parseInt(selection);
		}catch(NumberFormatException e){
			System.out.println("Your decision was invalid, please try again.");
			this.showBikeMenu();
		}
		
		switch((decision - 1)){
			case 1: this.showAddBikeDialogue();
			case 2: this.showDeleteBikeDialogue();
			case 3: this.showBikeModifyDialogue();
			case 4: this.showInventory();
		}
	}
	
	private void showAddBikeDialogue(){
		
		Bike bike;
		
		String name;
		String type;
		float price;
		
		System.out.println("What is your bikes name?");
		
		name = scan.nextLine();
		
		type = this.getBikeType();
		
		price = this.getBikePrice();
		
		bike = new Bike();
		
		bike.setName(name);
		bike.setType(type);
		bike.setPrice(price);
		
		bikeList.addBike(bike);
	}
	
	private String getBikeType(){
		
		int decision = 0;
		String selection;
		
		System.out.println("Select a Bike type by choosing the corresponding number:\n");
		
		for(int i = 0; i < Constants.TYPES.length; i++){
			System.out.println((i + 1) + Constants.TYPES[i]);
		}
		
		selection = scan.nextLine();
		
		try{
			decision = Integer.parseInt(selection);
		}catch(NumberFormatException e){
			System.out.println("Your decision was invalid, please try again.");
			this.getBikeType();
		}
		
		decision--;
		
		if(decision >= 0 && decision <= Constants.TYPES.length){
			selection = Constants.TYPES[decision];
		}else{
			System.out.println("Your decision was invalid, please try again.");
			this.getBikeType();
		}
		
		return selection;
		
	}
	
	private float getBikePrice(){
		
		float price = 0.0f;
		String sPrice;
		
		System.out.println("Enter a price for this bike.");
		
		sPrice = scan.nextLine();
		
		try{
			price = Float.parseFloat(sPrice);
		}catch(NumberFormatException e){
			System.out.println("Please enter your unit price like xxx.xx");
			this.getBikePrice();
		}
		
		return price;
	}
	
	private void showDeleteBikeDialogue(){
		
		
	}
	
	private void showBikeModifyDialogue(){
		
	}
	
	private void showInventory(){
		
	}
}
